package br.com.jmed.control;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.enterprise.context.ConversationScoped;
import javax.faces.bean.ManagedBean;
import java.io.Serializable;


@ManagedBean(name="testControl")
@ConversationScoped
public class TestControl implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private List<OBean> listBean = new ArrayList<TestControl.OBean>();

	
	class OBean {
		private Integer codigo;
		private String nome;
		
		public OBean(String nome, Integer codigo){
			this.nome = nome ;
			this.codigo = codigo;
		}
		
		public void setCodigo(Integer codigo){
			this.codigo = codigo;
		}
		
		public Integer getCodigo(){
			return codigo;
		}
		public void setNome(String nome){
			this.nome = nome;
		}
		
		public String getNome(){
			return nome;
		}
	}
	
		
	public List<OBean> autocomplete(Object prefix) {
        String pref = (String)prefix;
        listBean.add(new OBean("Felipe",1));
        listBean.add(new OBean("Feliciano",2));
        listBean.add(new OBean("Felismundo",3));
        listBean.add(new OBean("Raimundo",4));
        listBean.add(new OBean("Raijoao",5));
        listBean.add(new OBean("Rajoli",6));
        
        List<OBean> result = new ArrayList<OBean>();

        Iterator<OBean> iterator = listBean.iterator();
        while (iterator.hasNext()) {
            OBean elem = ((OBean) iterator.next());
            if ((elem.getNome() != null && elem.getNome().toLowerCase().indexOf(pref.toLowerCase()) == 0) || "".equals(pref))
            {
                result.add(elem);
            }
        }
        return result;
    }
}
